package pwd.allen.config;

import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import pwd.allen.service.IHelloService;

/**
 * API方式配置服务引用
 * @author lenovo
 * @create 2020-08-03 9:09
 **/
@Configuration
public class DubboConfig {

    /**
     * 方法一：使用 ReferenceBean
     * @return
     */
    @Bean
    public ReferenceBean<IHelloService> helloService() {
        ReferenceBean<IHelloService> referenceBean = new ReferenceBean<IHelloService>();
        referenceBean.setInterface(IHelloService.class);
        referenceBean.setVersion("pwd-1.0");
        referenceBean.setGroup("group1");
        referenceBean.setTimeout(2000);
        referenceBean.setLoadbalance(RandomLoadBalance.NAME);
        referenceBean.setStub("pwd.allen.service.stub.HelloServiceStub");
        referenceBean.setCheck(false);
        return referenceBean;
    }

    /**
     * 方法二：使用 ReferenceConfig
     * TODO 无效 好像不会被识别 IHelloService消费者没有被生成
     * @return
     */
//    @Bean
//    public ReferenceConfig<IHelloService> helloService() {
//        ReferenceConfig<IHelloService> referenceConfig = new ReferenceConfig<IHelloService>();
//        referenceConfig.setInterface(IHelloService.class);
//        referenceConfig.setVersion("pwd-1.0");
//        referenceConfig.setTimeout(1000);
//        referenceConfig.setLoadbalance("random");
//        referenceConfig.setStub("pwd.allen.service.stub.HelloServiceStub");
//        referenceConfig.setCheck(false);
//        return referenceConfig;
//    }
}
